<template>
    <div id="background">
        <el-container>
            <el-header id="examanswerCardHead">
                <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                       <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                        <img v-bind:src="backIcon" class="backSize" @click="back"/>
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol"> 
                        <span class="titleSize">答题卡</span>
                    </el-col>
                 </el-row>
            </el-header>
            <el-main id="examanswerCardMain">
                <el-scrollbar >
                    <div v-for="(tiMu,index) in tiMus" :key="index" >
                        <div>        
                            <el-col :xs="23" :sm="23" :md="23" :offset="1">
                                <div class="tiMuTitle">{{tiMu.type}}</div>
                            </el-col>
                        </div>
                        <div v-for="tiHao in tiMu.tiHao" :key="tiHao.num" @click="checkRealanswer(tiMu.type,tiHao.num,answer[tiMu.type][tiHao.num-1].answer)">
                            <el-col :xs="4" :sm="4" :md="4" class="imgCol">
                                <div v-if="answer[tiMu.type][tiHao.num-1].answer" class="tiHaoCompelet imgCol">
                                    <div>
                                        <span>{{tiHao.num}}</span>
                                        <img v-show="tiHao.biaoJi" v-bind:src="biaoJiIcon" style="height:10px;float:right" />
                                    </div>
                                </div>
<!--                                <div v-else-if="tiHao.status==0" class="tiHaoNormal imgCol">-->
<!--                                    <div>-->
<!--                                        <span>{{tiHao.num}}</span>-->
<!--                                        <img v-bind:src="biaoJiIcon" style="height:10px;float:right" />-->
<!--                                    </div>-->
<!--                                </div>-->
                                <div v-else class="tiHaoIncorrect imgCol">
                                    <div>
                                        <span>{{tiHao.num}}</span>
                                        <img v-show="tiHao.biaoJi" v-bind:src="biaoJiIcon" style="height:10px;float:right" />
                                    </div>
                                </div>
                            </el-col>
                        </div>
                    </div>
                </el-scrollbar>
            </el-main>
        </el-container>
    </div>
</template>
<script>
import backIcon from '../../../assets/img/mine/geRenZhongXin/back.png'
import biaoJiIcon from '../../../assets/img/tiKu/exam/biaoJi.png'
import { Toast } from 'vant';
export default {
    data(){
        return{
            //记录本次答题的情况
            judgeAnswer:[],
            questionType:[],
          //记录用户答题的正确与否
            answer:{},
          //记录用户答过的题目答案
          answerMap:{},
            TiMus:[],
            backIcon:backIcon,
            biaoJiIcon:biaoJiIcon,
            normalHeight:document.documentElement.clientHeight,
            tiMus:[],
        }
    },
    mounted(){
        // this.judgeAnswer=this.$route.query.judgeAnswer;
        // this.questionType=this.$route.query.questionType;
        // this.tiMus=this.$route.query.tiMus;
        // this.answerMap=this.$route.query.answerMap;
        this.judgeAnswer=JSON.parse(sessionStorage.getItem('judgeAnswer'));
        this.questionType=JSON.parse(sessionStorage.getItem('questionType'));
        this.tiMus=JSON.parse(sessionStorage.getItem('tiMus'));
        this.answerMap=JSON.parse(sessionStorage.getItem('answerMap'));
        console.log(this.judgeAnswer);
        console.log(this.questionType);
        console.log(this.tiMus);
        console.log(this.answerMap);
        this.handleTiMus();

         var normalHeight=document.documentElement.clientHeight;
        var bg = document.getElementById("background");
       // normalHeight=document.documentElement.clientHeight;
        console.log("height:"+normalHeight);
        bg.style.height = normalHeight+"px";
        bg.style.backgroundColor = "#FFFFFF"
        bg.style.margin = "0px";

        var head=document.getElementById("examanswerCardHead");
        var headHeight=normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

        var main=document.getElementById("examanswerCardMain");
        var mainHeight=normalHeight/30 *26 ;
        console.log("mainHeight:"+mainHeight);
        main.style.height=mainHeight+"px";
    },
    methods:{
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        //处理tiMus数组，将标记，做过，做错等状态划分
        handleTiMus(){
            var i=0,j=0,k=0,m=0,index=0;
             this.answer={};
            this.answer['单选']=[];
            this.answer['多选']=[];
            this.answer['判断']=[];
            for(i=0;i<this.questionType.length;i++){
              if(this.questionType[i]==='单选'){
                this.answer['单选'].push({
                  index:j,
                  answer:this.judgeAnswer[i]
                })
                j++;
              }
              else if(this.questionType[i]==='多选'){
                this.answer['多选'].push({
                  index:k,
                  answer:this.judgeAnswer[i]
                })
                k++;
              }
              else{
                this.answer['判断'].push({
                  index:m,
                  answer:this.judgeAnswer[i]
                })
                m++;
              }
            }
            //console.log(this.answer);
        },
      //查看指定题目的测试答案和解析
      checkRealanswer(type,num,answer){
          // console.log(type);
          // console.log(num);
          // console.log(answer);

          var index=num-1;
          var useranswer='';
        console.log(this.answerMap[type][index].userQuestionAnswer);
        if(type==='单选' || type==='判断'){
          useranswer=this.answerMap[type][index].userQuestionAnswer[0];
        }else{
          useranswer=this.answerMap[type][index].userQuestionAnswer;
        }
        console.log(useranswer);
          this.$router.push({
            path:'/tiKu/examanswer',
            query:{
              index:index,
              type:type,
              answer:answer,
              useranswer:useranswer
            }
          })

      }
    }
}
</script>
<style>
.tiMuTitle{
    border: #53cdf5 1px solid;
    background-color: #53cdf5;
    color: #fff;
    border-radius: 5px;
    padding: 5px;   
    height: 20px;
    width: 60px;
    text-align: center;
    margin-top: 20px;
}
.tiHaoCompelet{
    border: #53cdf5 1px solid;
    background-color: #53cdf5;
    color: #fff;
    border-radius: 50%;
    height: 30px;
    width: 30px;
    margin-top: 15px;
}
.tiHaoNormal{
    border: #53cdf5 1px solid;
    background-color: #fff;
    color: #53cdf5;
    border-radius: 50%;
    height: 30px;
    width: 30px;
    margin-top: 15px;
}
.tiHaoIncorrect{
    border: #f16161 1px solid;
    background-color: #f16161;
    color: #fff;
    border-radius: 50%;
    height: 30px;
    width: 30px;
    margin-top: 15px;
}
.el-header{
    padding: 0px;
}
.el-main,.el-header,.el-footer,.el-aside{
    padding: 0px;
}
#examanswerCardHead{
    background-color: #53cdf5;
    color: #707070;
}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
.words{
    color: #707070;
}
.backSize{
    height: 26px;
}
.titleSize{
    font-size:1.125em;
    color:#ffffff
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      font-size: 1em;
  }
}
</style>
